package logic

import (
	"MyBlogv2/blog-common/HttpCode"
	"MyBlogv2/blog-common/es"
	"MyBlogv2/blog-common/models"
	"context"
	"github.com/jinzhu/copier"

	"MyBlogv2/Servers/Article/article"
	"MyBlogv2/Servers/Article/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteArticleLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteArticleLogic {
	return &DeleteArticleLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DeleteArticleLogic) DeleteArticle(in *Article.DeleteArticleRequest) (*Article.CommonResponse, error) {
	var ids []int
	copier.Copy(&ids, &in.Ids)
	models.Db.Model(new(models.Article)).Where("id in (?)", ids).Delete(new(models.Article))
	es.DeleteArticle(ids)

	return &Article.CommonResponse{
		Code: int64(HttpCode.SUCCESS),
	}, nil
}
